home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / .wais / makedesc.org < prev    next >
Text File  |  1995-08-22  |  15KB  |  689 lines

  1. #!/net/pinatubo/opt/PUBperl5/bin/perl5
  2. # /export/scratch/illustra/bin/perl5
  3. # /opt/PUBperl5/bin/perl5
  4. #
  5. # makedesc.pl
  6. #
  7. # Generate The Wais Tree
  8. #
  9. # Copyright Creative Dynamics, Inc. 1995
  10. #
  11. #$dirn = $0;
  12. #$dirn =~ s#(.*)/.*$#$1#;
  13. #require "$dirn/common.pl";
  14.  
  15. $CATDB_NAME = "catalyst";
  16. $USER = "miadmin";
  17.  
  18. #
  19. # use the libmi stuff
  20. #
  21.  
  22. use Mi;
  23.  
  24. $lastCategory = "";
  25. $lastSubCategory = "";
  26. $chapterCount = 0;
  27. $fileOpen = 0;
  28.  
  29. ### Set up output directory
  30.  
  31. $outputDirectory = "wais-src";
  32. umask(022);
  33. mkdir($outputDirectory, 0777);        # make an output directory for book    
  34. chdir "$outputDirectory" || die "Can't cd to $outputDirectory\n";
  35. unlink(<*>);                # delete all existing files in the output directory
  36.  
  37. {
  38.    local($query,$num_col, @record);
  39.    local($db, $row_desc, $result, $row, $col, $row_num, $error);
  40.  
  41. ### the query
  42.  
  43. $query = "
  44. select  p.Product_id, p.SolCompatible,    
  45.     p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName,
  46.     p.ProdShortDesc, p.ProdLongDesc,
  47.     p.ProdHomePage, p.ProdImage, p.SrcAvail, p.ProdSrcLang,
  48.     p.ProdSpecHand,
  49.     v.VendorAddr1, v.VendorAddr2, v.VendorAddr3, v.VendorCity,
  50.     v.VendorPostCode,
  51.     v.VendorState, v.VendorZip, v.VendorCountry,
  52.     v.VendorPhone1code, v.VendorPhone1,
  53.     v.VendorPhone2code, v.VendorPhone2,
  54.     v.VendorFaxCode, v.VendorFax,
  55.     v.VendorEmailCode, v.VendorEmail,
  56.     v.VendorURL
  57. from   Vendor v using(lock=table),
  58.        Assoc_ProdVend a using(lock=table),
  59.        Products p using(lock=table)
  60. where  a.ProdId = p.Product_id
  61. and    a.VendId = v.Vendor_id
  62. and    p.Product_id < 10
  63. order by p.ProdCatName, p.ProdSubCat, p.ProdName
  64. ;";
  65.  
  66. # where  p.Product_id < 50 -- use to limit
  67. # alternate order: order by p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName
  68.  
  69. ### query the database
  70.  
  71.    ($db = Mi::open("$CATDB_NAME", "$USER", "") ) || die "Can't open Illustra database\n";
  72.  
  73.    (Mi::exec($db, "$query", 0) == 0) || die "Can't exec Illustra query\n";
  74.  
  75.    print "  Query Sent\n";
  76.  
  77.    (($result = Mi::get_result($db)) == 1) || die "Got bad result from Illustra\n";
  78.  
  79.    print "  Got Results\n";
  80.  
  81.    ($row_desc = Mi::get_row_desc_without_row($db)) || die "Error on row description \n";
  82.  
  83.    $num_col = Mi::column_count($row_desc);
  84.  
  85.    print "  Results Have $num_col Columns\n";
  86. exit;
  87.  
  88.    $row_num = 0;
  89.    while ($row = Mi::next_row($db, \$error))
  90.    {
  91.     $row_num++;
  92.     print "   Processing row $row_num...\n";
  93.     foreach $col (0..$num_col-1)
  94.     {
  95.           Mi::value($row, $col, $colval, $retlen);
  96.           $record[$col] = $colval;
  97.     }
  98.  
  99. # 0 p.Product_id,
  100. # 1 p.SolCompatible,
  101. # 2 p.ProdCatName,
  102. # 3 p.ProdSubCat,
  103. # 4 p.ProdName,
  104. # 5 v.VendorName,
  105. # 6 p.ProdShortDesc,
  106. # 7 p.ProdLongDesc,
  107. # 8 p.ProdHomePage,
  108. # 9 p.ProdImage,
  109. # 10 p.SrcAvail,
  110. # 11 p.ProdSrcLang,
  111. # 12 p.ProdSpecHand,
  112. # 13 v.VendorAddr1,
  113. # 14 v.VendorAddr2,
  114. # 15 v.VendorAddr3,
  115. # 16 v.VendorCity,
  116. # 17 v.VendorPostCode,
  117. # 18 v.VendorState,
  118. # 19 v.VendorZip,
  119. # 20 v.VendorCountry,
  120. # 21 v.VendorPhone1code,
  121. # 22 v.VendorPhone1,
  122. # 23 v.VendorPhone2code,
  123. # 24 v.VendorPhone2,
  124. # 25 v.VendorFaxCode,
  125. # 26 v.VendorFax,
  126. # 27 v.VendorEmailCode,
  127. # 28 v.VendorEmail,
  128. # 29 v.VendorURL
  129. # 30 v.VendorLOGO
  130.  
  131. ### Fix the data
  132.  
  133. # map double occurrences of ' to MIF version
  134.  
  135.     foreach $count (2..12)
  136.     {
  137.         $record[$count] =~ s/\'\'/\\q/g;
  138.     }
  139.  
  140. ### Trim trailing spaces
  141.     foreach $count (2..30)
  142.     {
  143.         $record[$count] =~ s/ *$//g;
  144.     }
  145.  
  146. ### Now print out the data for this product        
  147.  
  148. # 2 p.ProdCatName,
  149. # 3 p.ProdSubCat,
  150.  
  151.     if ($lastCategory ne $record[2])
  152.     {
  153.         ++$chapterCount;            # increment chapter count
  154.         $subCategoryFirstBreak = 1;        # reset
  155.         if ($fileOpen)
  156.         {
  157.             &print_chapterfooter();
  158.             close CHAPTER;    
  159.         }
  160.         $outputChapterFile = "chap" . $chapterCount . ".mif";
  161.         open(CHAPTER, ">$outputChapterFile") || do
  162.         {
  163.             die "Can't open CHAPTER file $outputChapterFile\n";
  164.         };
  165.         $fileOpen = 1;        # set to true
  166.         &print_chapterheader("H1", $record[2]);
  167.         $lastCategory = $record[2];
  168.  
  169.         &print_section($record[2]);
  170.     }
  171.     if ($lastSubCategory ne $record[3])
  172.     {
  173.         if (!$subCategoryFirstBreak)
  174.         {
  175.             &print_specialpara("H2", "<Pgf<PgfPlacement PageTop>>", $record[3]);    # page break
  176.         }
  177.         else
  178.         {
  179.             &print_para("H2", $record[3]);
  180.         }
  181.         $subCategoryFirstBreak = 0;
  182.         $lastSubCategory = $record[3];
  183.     }
  184.  
  185. # 4 p.ProdName,
  186. # 5 v.VendorName,
  187.     
  188.     &print_specialpara("H3", &build_productindex($record[5]), $record[5]);
  189.     &print_specialpara("H4", &build_vendorindex($record[4] . ":" . $record[5]), $record[4]);
  190.  
  191. # 6 p.ProdShortDesc,
  192. # 7 p.ProdLongDesc,
  193.     # choose the Long Description if it exists
  194.     $description = ($record[7] =~ /\S/) ? $record[7] : $record[6];
  195.     &print_multi("P", $description);
  196.  
  197. # 8 p.ProdHomePage,
  198.     if ($record[8] =~ /\S/)
  199.     {
  200.         &print_para("I", $record[8]);
  201.     }
  202.  
  203. # 9 p.ProdImage,
  204.  
  205.     ### NO PRODUCT IMAGE SUPPORT, YET
  206.     #&print_anchor(6);
  207.  
  208. ### TEMP NEED TO FIX THIS 
  209.     # &print_para("P", "Platforms supported: SPARC");
  210.  
  211. # 10 p.SrcAvail,
  212.     $answer = ($record[10] =~ /t/) ? "yes" : "no";
  213.     &print_para("P", "Source available: $answer");
  214.  
  215. # 11 p.ProdSrcLang,
  216.     &print_para("P", "Language: $record[11]");
  217.  
  218. # 12 p.ProdSpecHand,
  219. #
  220. # remove [ and ] brackets, also fix spaces and comma
  221. #
  222.     $record[12] =~ s/^\[//g;
  223.     $record[12] =~ s/ *]$//g;
  224.     $record[12] =~ s/^ *,//g;
  225.     $record[12] =~ s/ +,/, /g;
  226.  
  227.     if ($record[12] =~ /\S/)
  228.     {
  229.         &print_para("P", "Additional Requirements: $record[12]");
  230.     }
  231.  
  232. # 5 v.VendorName,
  233.     &print_para("I", $record[5]);
  234.  
  235. # 13 v.VendorAddr1,
  236. # 14 v.VendorAddr2,
  237. # 15 v.VendorAddr3,
  238.     foreach $count (13..15)
  239.     {
  240.          &print_para("I", $record[$count]) if ($record[$count] =~ /\S/);
  241.     }
  242. # 16 v.VendorCity,
  243. # 17 v.VendorPostCode,
  244. # 18 v.VendorState,
  245. # 19 v.VendorZip,
  246. # 20 v.VendorCountry,
  247.     # $record[16] =~ s/ $//g;
  248.     $address = $record[16] . ",";
  249.     foreach $count (18..20)
  250.     {
  251.         $address .= " " . $record[$count] if ($record[$count] =~ /\S/);
  252.     }
  253.     &print_para("I", $address);
  254.  
  255.     &print_para("I","Postal Code: $record[17]") if ($record[17] =~ /\S/);
  256.  
  257. # 21 v.VendorPhone1code,
  258. # 22 v.VendorPhone1,
  259. # 23 v.VendorPhone2code,
  260. # 24 v.VendorPhone2,
  261. # 25 v.VendorFaxCode,
  262. # 26 v.VendorFax,
  263. # 27 v.VendorEmailCode,
  264. # 28 v.VendorEmail,
  265.  
  266. $text = "";
  267. $text = $record[21] . " " if ($record[21] =~ /\S/);
  268. &print_para("I","Phone1: $text$record[22]") if ($record[22] =~ /\S/);
  269. $text = "";
  270. $text = $record[23] . " " if ($record[23] =~ /\S/);
  271. &print_para("I","Phone2: $text$record[24]") if ($record[24] =~ /\S/);
  272. $text = "";
  273. $text = $record[25] . " " if ($record[25] =~ /\S/);
  274. &print_para("I","Fax: $text$record[26]") if ($record[26] =~ /\S/);
  275. $text = "";
  276. $text = $record[27] . " " if ($record[27] =~ /\S/);
  277. &print_para("I","E-mail: $text$record[28]") if ($record[28] =~ /\S/);
  278.  
  279. # 29 v.VendorURL
  280.  
  281.     &print_para("I",$record[29]) if ($record[29] =~ /\S/);
  282.  
  283. # 30 v.VendorLOGO
  284.  
  285.     ### NO VENDOR IMAGE SUPPORT, YET
  286.     #&print_anchor(6);
  287.  
  288. # End of Product
  289.     &print_para("HR", "");
  290.  
  291.    }
  292.  
  293.    Mi::close($db);
  294.  
  295.    print "Processed $row_num records\n";
  296. }
  297.  
  298.  
  299. ### TEMP TEST OF GRAPHIC
  300.     #&print_anchor(6);
  301.  
  302. # final stuff...
  303. if ($fileOpen)
  304. {
  305.     &print_chapterfooter();
  306.     close CHAPTER;    
  307. }
  308.  
  309. # process book file
  310. &createbook();
  311.  
  312. print "Book Complete\n";
  313.  
  314.  
  315. #------------------------------------------------------------------
  316. # SUBROUTINES
  317. #------------------------------------------------------------------
  318.  
  319. #------------------------------------------------------------------
  320. # build_productindex 
  321. #
  322. # subroutine build_productindex builds MIF for FrameMaker product index markers
  323.  
  324. sub build_productindex {
  325.     return &build_indexmarker(2, @_[0]);
  326. }
  327.  
  328.  
  329. #------------------------------------------------------------------
  330. # build_vendorindex 
  331. #
  332. # subroutine build_vendorindex builds MIF for FrameMaker vendor index markers
  333.  
  334. sub build_vendorindex {
  335.     return &build_indexmarker(2, @_[0]);
  336. }
  337.  
  338.  
  339. #------------------------------------------------------------------
  340. # build_indexmarker 
  341. #
  342. # subroutine build_indexmarker builds MIF for FrameMaker index markers
  343.  
  344. sub build_indexmarker {
  345.  
  346.     local($markerType, $indexEntry) = @_;
  347.  
  348.     return "<Marker <MType $markerType> <MText \`$indexEntry\'>>";
  349. }
  350.  
  351.  
  352. #------------------------------------------------------------------
  353. # print_specialpara 
  354. #
  355. # subroutine print_specialpara prints MIF for FrameMaker paragraph with a special character ie bullet
  356.  
  357. sub print_specialpara {
  358.  
  359.     local($tag) = @_[0];
  360.     local($specialchar) = @_[1]; 
  361.     local($string) = @_[2]; 
  362.  
  363.     print CHAPTER " <Para 
  364.   <PgfTag \`$tag\'>
  365.    <ParaLine $specialchar
  366.     <String \`$string\'>
  367.    >
  368.  > # end of Para\n";
  369. }
  370.  
  371.  
  372. #------------------------------------------------------------------
  373. # print_para 
  374. #
  375. # subroutine print_para prints MIF for FrameMaker paragraph
  376.  
  377. sub print_para {
  378.  
  379.     local($tag) = @_[0];
  380.     local($string) = @_[1]; 
  381.  
  382.     print CHAPTER " <Para 
  383.   <PgfTag \`$tag\'>
  384.    <ParaLine
  385.     <String \`$string\'>
  386.    >
  387.  > # end of Para\n";
  388. }
  389.  
  390. #------------------------------------------------------------------
  391. # print_uniquepara 
  392. #
  393. # subroutine print_para prints MIF for FrameMaker paragraph
  394.  
  395. sub print_uniquepara {
  396.  
  397.     local($device) = @_[0];
  398.     local($tag) = @_[1];
  399.     local($unique) = @_[2]; 
  400.     local($specialchar) = @_[3]; 
  401.     local($string) = @_[4]; 
  402.  
  403.     print $device " <Para 
  404.   <Unique $unique>
  405.   <PgfTag \`$tag\'>
  406.    <ParaLine $specialchar
  407.     <String \`$string\'>
  408.    >
  409.  > # end of Para\n";
  410. }
  411.  
  412.  
  413.  
  414. #------------------------------------------------------------------
  415. # print_multi 
  416. #
  417. # subroutine print_multi prints MIF for multiple FrameMaker paragraph
  418.  
  419. sub print_multi {
  420.  
  421.     local($tag) = @_[0];
  422.     local(@strings) = split(/\n/, @_[1]); 
  423.  
  424.     foreach $string (@strings)
  425.     {
  426.         if ($string =~ s/^--//)
  427.         {
  428.             &print_specialpara($tag, "<Char Bullet>", $string);
  429.         }
  430.         else
  431.         {
  432.             &print_para($tag, $string);
  433.         }
  434.     }
  435. }
  436.  
  437. #------------------------------------------------------------------
  438. # print_anchor 
  439. #
  440. # subroutine print_anchor prints MIF for FrameMaker anchored frame
  441.  
  442. sub print_anchor {
  443.  
  444.     local($id) = @_[0];
  445.  
  446.     print CHAPTER " <Para 
  447.   <ParaLine 
  448.    <AFrame $id>
  449.   >
  450.  > # end of Para\n";
  451. }
  452.  
  453. #------------------------------------------------------------------
  454. # print_chapterheader 
  455. #
  456. # subroutine print_chapterheader prints header for every chapter file
  457.  
  458. sub print_chapterheader {
  459.  
  460.     local($tag) = @_[0];
  461.     local($string) = @_[1]; 
  462.  
  463.     print CHAPTER <<CHAPTERHEADER;
  464. <MIFFile 4.00> # Generated by The Carl Group, Inc.
  465. # for the Sun Solutions Catalog
  466. include(../chaphead.mif)
  467. <TextFlow 
  468.  <TFTag `A'> <TFAutoConnect Yes > <Notes > # end of Notes
  469.  <Para 
  470.   <Unique 55>
  471.   <PgfTag `$tag'>
  472.   <ParaLine 
  473.    <TextRectID 28>
  474.     <String `$string'>
  475.   >
  476.  > # end of Para
  477. CHAPTERHEADER
  478.  
  479. }
  480.  
  481. #------------------------------------------------------------------
  482. # print_chapterfooter
  483. #
  484. # subroutine print_chapterfooter prints footer for every chapter file
  485.  
  486. sub print_chapterfooter {
  487.  
  488.    print CHAPTER <<CHAPTERFOOTER;
  489. > # end of TextFlow
  490. # End of Generated MIF File for the Sun Solutions Catalog
  491. CHAPTERFOOTER
  492.  
  493. }
  494.  
  495. #------------------------------------------------------------------
  496. # print_section
  497. #
  498. # subroutine print_section prints the section file for every chapter
  499.  
  500. sub print_section {
  501.  
  502.     local($category) = @_;
  503.     local($outputSectionFile, $cnt, $word, @words);
  504.  
  505.     $outputSectionFile = "sect" . $chapterCount . ".mif";
  506.     open(SECTION, ">$outputSectionFile") || do
  507.     {
  508.         die "Can't open SECTION file $outputSectionFile\n";
  509.     };
  510.  
  511.     #----------------------
  512.     # HEADER
  513.     print SECTION <<SECTIONHEADER;
  514. <MIFFile 4.00> # Developed by the Carl Group, Inc
  515. # for the Sun Solutions Catalog
  516. include(../secthead.mif)
  517.  
  518. SECTIONHEADER
  519.  
  520.  
  521.     @words = split(" ", $category);    # place into array
  522.     @words = grep(!/^ $/, @words);    # remove spaces
  523.     $cnt = @words;            # count elements
  524.     if ($cnt == 1)
  525.     {
  526.         &print_uniquepara(SECTION, "Chap Title", 123, "", "");
  527.         &print_uniquepara(SECTION, "Chap Title", 124, "", "");
  528.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[0]);
  529.     }
  530.     elsif ($cnt == 2)
  531.     {
  532.         &print_uniquepara(SECTION, "Chap Title", 123, "", "");
  533.         &print_uniquepara(SECTION, "Chap Title", 124, "", @words[0]);
  534.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[1]);
  535.     }
  536.     elsif ($cnt == 3)
  537.     {
  538.         &print_uniquepara(SECTION, "Chap Title", 123, "", @words[0]);
  539.         &print_uniquepara(SECTION, "Chap Title", 124, "", @words[1]);
  540.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[2]);
  541.     }
  542.  
  543.     print SECTION <<SECTIONBODY;
  544. > # end of TextFlow
  545. <TextFlow 
  546.  <Para 
  547.   <Unique 95>
  548.   <PgfTag `Chap Head'>
  549.   <ParaLine 
  550.    <TextRectID 12>
  551.   >
  552.  > # end of Para
  553.  <Para 
  554.   <Unique 100>
  555.   <PgfTag `Chap Head'>
  556.   <ParaLine 
  557. SECTIONBODY
  558.     print SECTION "   <String `SECTION $chapterCount'>  # Section with Number\n  >\n > # end of Para\n";
  559.  
  560.     #-------------------------
  561.     # FOOTER
  562.     print SECTION <<SECTIONFOOTER;
  563. > # end of TextFlow
  564. # End of MIFFile
  565. SECTIONFOOTER
  566.  
  567.     close SECTION;
  568. }
  569.  
  570. #------------------------------------------------------------------
  571. # createbook
  572. #
  573. # subroutine createbook creates the MIF version of a book
  574.  
  575. sub createbook {
  576.  
  577.         local($bookFile, $chapter);
  578.  
  579.     $bookFile = "ssc.mif";
  580.     open(BOOK, ">$bookFile") || do
  581.     {
  582.         die "Can't open CHAPTER file $bookFile\n";
  583.     };
  584.  
  585.     &print_bookheader();
  586.     for(1..$chapterCount)
  587.     {
  588.         &print_bookcomponent($_);
  589.     }
  590.     &print_bookfooter();
  591.  
  592. }
  593.  
  594.  
  595. #------------------------------------------------------------------
  596. # print_bookheader
  597. #
  598. # subroutine print_bookheader prints MIF header for the book file
  599.  
  600. sub print_bookheader {
  601.  
  602.     print BOOK <<BOOKHEADER
  603. <Book 4.0> # Generated by The Carl Group, Inc
  604. # for the Sun Solutions Catalog
  605. <BookComponent 
  606.  <FileName `<c\\>sscTOC.doc'>
  607.  <FileNameSuffix `TOC'>
  608.  <DeriveLinks No >
  609.  <DeriveType TOC >
  610.  <DeriveTag `H1'>
  611.  <DeriveTag `H2'>
  612.  <StartPageSide ReadFromFile >
  613.  <PageNumbering Continue >
  614.  <PgfNumbering Continue >
  615.  <PageNumPrefix `'>
  616.  <PageNumSuffix `'>
  617.  <DefaultPrint Yes >
  618.  <DefaultApply Yes >
  619.  <DefaultDerive Yes >
  620. > # end of BookComponent
  621. BOOKHEADER
  622.  
  623. }
  624.  
  625. #------------------------------------------------------------------
  626. # print_bookcomponent
  627. #
  628. # subroutine print_bookcomponent prints MIF header for every component in the book file
  629.  
  630. sub print_bookcomponent {
  631.  
  632.         local($component, $section, $chapter) = @_[0];
  633.  
  634.     $section = "sect" . $component . ".doc";
  635.     $chapter = "chap" . $component . ".doc";
  636.  
  637.     print BOOK <<BOOKCOMPONENT
  638. <BookComponent 
  639.  <FileName `<c\\>$section'>
  640.  <StartPageSide ReadFromFile >
  641.  <PageNumbering Continue >
  642.  <PgfNumbering Continue >
  643.  <PageNumPrefix `'>
  644.  <PageNumSuffix `'>
  645.  <DefaultPrint Yes >
  646.  <DefaultApply Yes >
  647. > # end of BookComponent
  648. <BookComponent 
  649.  <FileName `<c\\>$chapter'>
  650.  <StartPageSide ReadFromFile >
  651.  <PageNumbering Continue >
  652.  <PgfNumbering Continue >
  653.  <PageNumPrefix `'>
  654.  <PageNumSuffix `'>
  655.  <DefaultPrint Yes >
  656.  <DefaultApply Yes >
  657. > # end of BookComponent
  658. BOOKCOMPONENT
  659.  
  660. }
  661.  
  662. #------------------------------------------------------------------
  663. # print_bookfooter
  664. #
  665. # subroutine print_bookfooter prints MIF footer for the book file
  666.  
  667. sub print_bookfooter {
  668.  
  669.    print BOOK <<BOOKFOOTER;
  670. <BookComponent 
  671.  <FileName `<c\\>sscIX.doc'>
  672.  <FileNameSuffix `IX'>
  673.  <DeriveLinks No >
  674.  <DeriveType IDX >
  675.  <DeriveTag `Index'>
  676.  <StartPageSide ReadFromFile >
  677.  <PageNumbering Continue >
  678.  <PgfNumbering Continue >
  679.  <PageNumPrefix `'>
  680.  <PageNumSuffix `'>
  681.  <DefaultPrint Yes >
  682.  <DefaultApply Yes >
  683.  <DefaultDerive Yes >
  684. > # end of BookComponent
  685. # end of Book
  686. BOOKFOOTER
  687.  
  688. }
  689.